-
-
Notifications
You must be signed in to change notification settings - Fork 7
Fix log in iOS11 simulators. #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/simctl.ts
Outdated
@@ -120,11 +121,19 @@ export class Simctl implements ISimctl { | |||
return devices; | |||
} | |||
|
|||
public getLog(deviceId: string): any { | |||
return this.simctlSpawn("spawn", [deviceId, "log", "stream"]); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the great suggestions, NathanaelA!
I will add --style syslog
as this will really make the log very similar to the one in Simulators with previous iOS versions.
I can't add --predicate 'senderImagePath contains "NativeScript"
directly as this tool is not framework specific and is published as separate NPM package. I can however add an optional predicate argument to the method.
lib/iphone-simulator-xcode-simctl.ts
Outdated
deviceLogChildProcess = this.getDeviceLogProcess(deviceId); | ||
if (deviceLogChildProcess.stdout) { | ||
deviceLogChildProcess.stdout.on("data", (data: NodeBuffer) => { | ||
let dataAsString = data.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be const
lib/iphone-simulator-xcode-simctl.ts
Outdated
if (deviceLogChildProcess.stderr) { | ||
deviceLogChildProcess.stderr.on("data", (data: string) => { | ||
let dataAsString = data.toString(); | ||
if (pid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided that we log the data regardless of whether you enter the if
or the else
I'd suggest we remove the filter as a whole.
The code could be narrowed down to:
deviceLogChildProcess.stderr.on("data", (data: string) => {
process.stdout.write(data.toString());
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @rosen-vladimirov and actually the logging outside the if
and else
statements is a mistake. Will fix it.
lib/iphone-simulator-xcode-simctl.ts
Outdated
} | ||
|
||
public getDeviceLogProcess(deviceId: string): any { | ||
return common.getDeviceLogProcess(deviceId); | ||
const device = this.getDeviceFromIdentifier(deviceId) || {}; | ||
const deviceVersion = this.getDeviceFromIdentifier(deviceId).runtimeVersion || ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use device
here
const deviceVersion = device.runtimeVersion || "";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad.
lib/iphone-simulator-xcode-simctl.ts
Outdated
if(majorVersion && parseInt(majorVersion) >= 11) { | ||
this.deviceLogChildProcess = this.simctl.getLog(deviceId); | ||
} else { | ||
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be const
lib/iphone-simulator-xcode-simctl.ts
Outdated
} | ||
|
||
public getDeviceLogProcess(deviceId: string): any { | ||
return common.getDeviceLogProcess(deviceId); | ||
const device = this.getDeviceFromIdentifier(deviceId) || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization of these variables can be done inside the if
statement down below, because they're only used there
lib/simctl.ts
Outdated
return result.stdout.toString().trim(); | ||
} | ||
return ''; | ||
} | ||
|
||
private simctlSpawn(command: string, args: string[], opts?: any): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here can be narrowed to child_process.ChildProcess
instead of any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, you can specify opts?: child_process.SpawnOptions
instead of opts?: any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
lib/iphone-simulator-xcode-simctl.ts
Outdated
} | ||
|
||
if (deviceLogChildProcess.stderr) { | ||
deviceLogChildProcess.stderr.on("data", (data: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event handlers for deviceLogChildProcess.stderr.on("data"
and deviceLogChildProcess.stdout.on("data"
are identical - you can extract the handler as a separate function and pass it to both cases
lib/simctl.ts
Outdated
@@ -120,11 +121,25 @@ export class Simctl implements ISimctl { | |||
return devices; | |||
} | |||
|
|||
public getLog(deviceId: string, predicate?: string): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here is child_process.ChildProcess
lib/iphone-simulator-xcode-simctl.ts
Outdated
} | ||
|
||
public getDeviceLogProcess(deviceId: string): any { | ||
return common.getDeviceLogProcess(deviceId); | ||
public getDeviceLogProcess(deviceId: string, predicate?: string): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here is child_process.ChildProcess
lib/iphone-simulator-xcode-simctl.ts
Outdated
@@ -116,11 +120,64 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I | |||
} | |||
|
|||
public printDeviceLog(deviceId: string, launchResult?: string): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the return type to child_process.ChildProcess
here as well
lib/simctl.ts
Outdated
public getLog(deviceId: string, predicate?: string): any { | ||
let predicateArgs: string[] = []; | ||
|
||
if (!_.isUndefined(predicate)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a simple check like if (predicate) {
would suffice here, but this is a personal preference
f9a812e
to
56db899
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me
56db899
to
f2ccf13
Compare
Part of the fix NativeScript/nativescript-cli#3141 (comment)
Fix uses the method described in this example.